﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}


<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Quick Start - Layui</title>
    @* <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet"> *@
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.9.20/dist/css/layui.min.css">
</head>
<body>
    <!--弹出框-->
    <div style="padding:20px;" id="popup">
        <form class="layui-form" lay-filter="demo-val-filter" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">企业名称</label>
                <div class="layui-input-block">
                    <input type="text" name="enterpriseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">企业简称</label>
                <div class="layui-input-block">
                    <input type="text" name="enterpriseAbbreviation" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">注册地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">法定负责人</label>
                <div class="layui-input-block">
                    <input type="text" name="legalRepresentative" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="required|phone" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">电子邮件</label>
                <div class="layui-input-block">
                    <input type="text" name="email" lay-verify="required|email" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">成立日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-date"></i>
                        </div>
                        <input type="date" name="establishmentDate" lay-verify="date" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" id="component" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-val">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <script>
        // 使用layui的layer模块
        layui.use('form', function () {
            var $ = layui.$;
            var form = layui.form;

            //获取路径传过来的值
            console.log(location.search.split("=")[1])

            // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });

            // 提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值
                field.turnoverTime = "" || null;
                field.parentId = location.search.split("=")[1];
                field.isDeleted = 0;
                console.log(field.establishmentDate) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite' + "/api/Enterprises/CreateEnterprise",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: function (res) {
                        console.log(res)
                        if (res.code==0) {
                            // 处理响应，例如提示成功信息
                            layui.layer.msg(res.msg, { icon: 6, time: 1000 });
                            // 使用setTimeout来延迟关闭操作
                            setTimeout(function () {
                                // 操作成功后关闭当前弹出层
                                var index = parent.layer.getFrameIndex(window.name); // 获取当前弹出层的索引
                                parent.layer.close(index); // 关闭弹出层
                            }, 1000);
                        }
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });
        });
    </script>
</body>
</html>